import sys
import os
from os.path import dirname, abspath

'''
    添加项目路径到系统路径的代码段
    
    project_dir = dirname(dirname(abspath('__file__')))

    if(project_dir.split("\\")[-1]=="deepdot_vision"):
        sys.path.insert(0,project_dir)
        print("Adding project folder to PATH:\n{}".format(project_dir))
    else:
        print("Please checking extracted project dir:\n{}".format(project_dir))
'''  
    
def _init_project_dir(root_folder:str="deepdot_vision", max_level:int = 5):
    current_file_path = abspath('__file__')
    current_folder = dirname(current_file_path)
    count = 0
    while current_folder.split("\\")[-1]!=root_folder and count < max_level:
        current_folder = dirname(current_folder)
    if(current_folder.split("\\")[-1]==root_folder):
        project_dir = current_folder
        if(project_dir not in sys.path ):       
            sys.path.insert(0,project_dir)
            print("Adding project folder to PATH:\n{}".format(project_dir))
        else:
            print("Target project folder already added in PATH:\n{}".format(project_dir))
    else:
        print("Please checking current dir is under project_root:\n{}".format(dirname(current_file_path)))  

'''  
if __name__=='__main__':
    _init_project_dir()

'''



   






